import "@/index.scss";
import "@/components/index.ts";
import { createBootstrapLayout, runMain } from "@/utils";

class Login extends HTMLElement {
    readonly root: ShadowRoot;
    private readonly template: string = `
        <link href="/bootstrap/bootstrap.min.css" rel="stylesheet" />
        <div class="container mt-5">
            <div class="row justify-content-center">
                <div class="col-md-4">
                    <div class="card">
                        <div class="card-body">
                            <h5 class="card-title text-center">Login</h5>
                                <form id="loginForm">
                                    <div class="mb-3">
                                        <label for="email" class="form-label">Email address</label>
                                        <input type="email" class="form-control" id="email" placeholder="Enter your email" required>
                                    </div>
                                    <div class="mb-3">
                                        <label for="password" class="form-label">Password</label>
                                        <input type="password" class="form-control" id="password" placeholder="Enter your password" required>
                                    </div>
                                    <button type="submit" class="btn btn-primary w-100">Login</button>
                                </form>
                            <div id="message" class="mt-3 text-center text-danger"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    `;

    constructor() {
        super();
        this.root = this.attachShadow({ mode: "open" });
        $(this.root).append($(this.template));
    }
}

class Register extends HTMLElement {}

customElements.define("crm-login", Login);
customElements.define("crm-register", Register);

runMain((app) => {
    createBootstrapLayout(
        {
            pages: [
                { name: "Index", href: "/pages/index.html" },
                { name: "Administrator", href: "/pages/administrator.html" },
                { name: "Salesperson", href: "/pages/salesperson.html" },
                { name: "Customer", href: "/pages/customer.html" },
            ],
            functions: [
                {
                    name: "Login",
                    element: () => document.createElement("crm-login"),
                },
                {
                    name: "Register",
                    element: () => new Register(),
                },
            ],
        },
        app,
    );
});
